package com.lzq.course.business.controller.admin;

import com.lzq.course.server.dto.CourseContentFileDto;
import com.lzq.course.server.dto.PageDto;
import com.lzq.course.server.dto.ResponseDto;
import com.lzq.course.server.service.CourseContentFileService;
import com.lzq.course.server.util.ValidatorUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/course-content-file")
public class CourseContentFileController {

    public static final String BUSINESS_NAME = "课程内容文件";

    @Resource
    private CourseContentFileService courseContentFileService;

    /**
     * 查询所有富文本下的文件
     * @return
     */
    @PostMapping("/all")
    public ResponseDto list() {
        ResponseDto responseDto = courseContentFileService.all();

        return responseDto;
    }

    /**
     * 保存
     * @param courseContentFileDto
     * @return
     */
    @PostMapping("/save")
    public ResponseDto save(@RequestBody CourseContentFileDto courseContentFileDto) {

        //保存校验
        ValidatorUtil.require(courseContentFileDto.getCourseId(), "课程id");
        ValidatorUtil.length(courseContentFileDto.getUrl(),"地址", 1, 100);
        ValidatorUtil.length(courseContentFileDto.getName(),"文件名", 1, 100);

        ResponseDto responseDto = new ResponseDto();
        courseContentFileService.save(courseContentFileDto);

        responseDto.setContent(courseContentFileDto);
        return responseDto;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseDto delete(@PathVariable String id) {
        ResponseDto responseDto = new ResponseDto();
        courseContentFileService.delete(id);

        return responseDto;
    }
}
